---
category: Level 1 — Basic
created: '2020-02-18'
keywords:
title: Detect clicks outside of an element
---

Check if a click was outside of the `ele` element:

```js
document.addEventListener('click', function (evt) {
    const isClickedOutside = !ele.contains(evt.target);

    // `isClickedOutside` is true if the clicked target is outside of `ele`
});
```

## See also

-   [Check if an element is a descendant of another](https://phuoc.ng/collection/html-dom/check-if-an-element-is-a-descendant-of-another/)
-   [Check if users click outside of selected text](https://phuoc.ng/collection/html-dom/check-if-users-click-outside-of-selected-text/)
-   [Show a custom context menu at clicked position](https://phuoc.ng/collection/html-dom/show-a-custom-context-menu-at-clicked-position/)
